package com.hqs.listener.helper;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Progress;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okserver.OkDownload;
import com.lzy.okserver.download.DownloadListener;
import com.lzy.okserver.download.DownloadTask;

import java.io.File;

/**
 * Created by apple on 16/9/27.
 */

public class HttpHelper {

    public static void download(String url, String dir, String fileName, DownloadListener listener){

        OkDownload.getInstance().removeAll();

        GetRequest<File> request = OkGo.get(url);
        OkDownload.getInstance().request(fileName, request);

        DownloadTask task = OkDownload.request(fileName, request)
                .priority(1000)
                .folder(dir)
                .fileName(fileName)
                .register(listener);
        task.save().start();
    }

    public interface DownloadFileListener {
        void onProgress(Progress progress, String fileName);
    }
}



